<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Object Pool Allocator: opalloc.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Object Pool Allocator
   &#160;<span id="projectnumber">1.3.5.1.4.1.45340.1.1.2</span>
   </div>
   <div id="projectbrief">Space-reusing dynamic allocation in C.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">opalloc.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="opalloc_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/* vim: ft=c */</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#ifndef OPALLOC_INCLUDED</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#define OPALLOC_INCLUDED</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment">/******************************************************************************</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment">* (c)2022 Michael T. Richter</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment">*</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment">* This software is distributed under the terms of WTFPLv2.  The full terms and</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment">* text of the license can be found at http://www.wtfpl.net/txt/copying</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment">******************************************************************************/</span></div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="preprocessor">#include &lt;stdbool.h&gt;</span></div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="preprocessor">#include &lt;stddef.h&gt;</span></div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="group__llinterface.html#ga27f4549e49590119789d18e1ff77e7c0">   47</a></span>&#160;<span class="keyword">typedef</span> <span class="keyword">enum</span> <a class="code" href="group__llinterface.html#ga27f4549e49590119789d18e1ff77e7c0">op_ll_allocator_mode</a></div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;{</div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0acd93e093157aa38ebc1a5b9633e7755e">   49</a></span>&#160;    <a class="code" href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0acd93e093157aa38ebc1a5b9633e7755e">OP_DOUBLING_INDIVIDUAL</a>, </div><div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0a840daf6b7aadca424c38454f5755aa8c">   50</a></span>&#160;    <a class="code" href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0a840daf6b7aadca424c38454f5755aa8c">OP_DOUBLING_CHUNK</a>,      </div><div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0af55c441a5deea02b96b61bdd18fb5aff">   51</a></span>&#160;    <a class="code" href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0af55c441a5deea02b96b61bdd18fb5aff">OP_LINEAR_INDIVIDUAL</a>,   </div><div class="line"><a name="l00052"></a><span class="lineno"><a class="line" href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0aa7777bc69f8c511bd503ca7ac68a1096">   52</a></span>&#160;    <a class="code" href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0aa7777bc69f8c511bd503ca7ac68a1096">OP_LINEAR_CHUNK</a>,        </div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;} <a class="code" href="group__llinterface.html#ga27f4549e49590119789d18e1ff77e7c0">op_ll_allocator_mode</a>;</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"><a class="line" href="group__llinterface.html#ga9209b1a64c38a2148ea7c25dab8edd0f">   56</a></span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="struct__op__allocator.html">_op_allocator</a> *<a class="code" href="group__llinterface.html#ga9209b1a64c38a2148ea7c25dab8edd0f">op_allocator</a>;</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;</div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="structop__allocator__stats.html">   59</a></span>&#160;<span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structop__allocator__stats.html">op_allocator_stats</a></div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;{</div><div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="structop__allocator__stats.html#a15a79503b219194c76a468bdc3bec4a5">   61</a></span>&#160;    <span class="keywordtype">size_t</span> <a class="code" href="structop__allocator__stats.html#a15a79503b219194c76a468bdc3bec4a5">object_size</a>;     </div><div class="line"><a name="l00062"></a><span class="lineno"><a class="line" href="structop__allocator__stats.html#a0121145290507112e4e08e9196c00ab5">   62</a></span>&#160;    <span class="keywordtype">size_t</span> <a class="code" href="structop__allocator__stats.html#a0121145290507112e4e08e9196c00ab5">maximum_objects</a>; </div><div class="line"><a name="l00063"></a><span class="lineno"><a class="line" href="structop__allocator__stats.html#a562d1a6a3feee1f423eb96d40b9f91d2">   63</a></span>&#160;    <span class="keywordtype">size_t</span> <a class="code" href="structop__allocator__stats.html#a562d1a6a3feee1f423eb96d40b9f91d2">active_objects</a>;  </div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;} <a class="code" href="group__llinterface.html#gad09821373eccfb78a54f20dbf5d4bdd2">op_allocator_stats</a>;</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;<span class="keywordtype">void</span> <a class="code" href="group__llinterface.html#gac6ef31d67566dde5e73047c336b39740">op_error_handler</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *file, <span class="keyword">const</span> <span class="keywordtype">int</span> line, <span class="keyword">const</span> <span class="keywordtype">char</span> *error_message);</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;<span class="keywordtype">void</span> *<a class="code" href="group__llinterface.html#ga92340cf30ad310a00d2f24ac2f480156">op_ll_allocate_object</a>(op_allocator allocator);</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;<span class="keywordtype">void</span> <a class="code" href="group__llinterface.html#gac5c6703fea3c0a2e39d07f4bfac031a8">op_ll_deallocate_object</a>(op_allocator allocator, <span class="keyword">const</span> <span class="keywordtype">void</span> *<span class="keywordtype">object</span>);</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;<span class="keywordtype">void</span> <a class="code" href="group__llinterface.html#ga278159fc6bbfb1c2e2513530cbee0e96">op_ll_deinitialize_allocator</a>(op_allocator allocator);</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;<a class="code" href="structop__allocator__stats.html">op_allocator_stats</a> <a class="code" href="group__llinterface.html#gaa0d8acd3d49cc322551e0033f61bdaca">op_ll_get_allocator_stats</a>(<span class="keyword">const</span> op_allocator allocator);</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;op_allocator <a class="code" href="group__llinterface.html#gaf0ba071e1d766a1e7cb9ba7c40d5b4ba">op_ll_initialize_allocator</a>(<span class="keyword">const</span> <span class="keywordtype">size_t</span> <a class="code" href="structop__allocator__stats.html#a15a79503b219194c76a468bdc3bec4a5">object_size</a>, <span class="keyword">const</span> <span class="keywordtype">size_t</span> initial_count,</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;                                        <span class="keyword">const</span> <a class="code" href="group__llinterface.html#ga27f4549e49590119789d18e1ff77e7c0">op_ll_allocator_mode</a> mode);</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;</div><div class="line"><a name="l00176"></a><span class="lineno"><a class="line" href="group__hlinterface.html#ga1ccfddfc8243b5f14f9cabbc58d3e08a">  176</a></span>&#160;<span class="preprocessor">#define OP_HL_DECLARE_ALLOCATOR(TYPE, COUNT, MODE)                            \</span></div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;<span class="preprocessor">static op_allocator TYPE##_allocator;                                         \</span></div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;<span class="preprocessor">static bool TYPE##_allocator_initialized = false;                             \</span></div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;<span class="preprocessor">static inline void initialize_##TYPE##_allocator(void)                        \</span></div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;<span class="preprocessor">{ TYPE##_allocator = op_ll_initialize_allocator(sizeof(TYPE), COUNT, MODE); } \</span></div><div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;<span class="preprocessor">static inline TYPE *allocate_##TYPE(void)                                     \</span></div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;<span class="preprocessor">{ if (!TYPE##_allocator_initialized)                                          \</span></div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;<span class="preprocessor">  { initialize_##TYPE##_allocator(); TYPE##_allocator_initialized = true; }   \</span></div><div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;<span class="preprocessor">  return op_ll_allocate_object(TYPE##_allocator); }                           \</span></div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;<span class="preprocessor">static inline void deallocate_##TYPE(TYPE *object)                            \</span></div><div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;<span class="preprocessor">{ op_ll_deallocate_object(TYPE##_allocator, object); }                        \</span></div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;<span class="preprocessor">static inline void deinitialize_##TYPE##_allocator(void)                      \</span></div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;<span class="preprocessor">{ op_ll_deinitialize_allocator(TYPE##_allocator); }</span></div><div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;</div><div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="group__llinterface_html_gac6ef31d67566dde5e73047c336b39740"><div class="ttname"><a href="group__llinterface.html#gac6ef31d67566dde5e73047c336b39740">op_error_handler</a></div><div class="ttdeci">void op_error_handler(const char *file, const int line, const char *error_message)</div><div class="ttdoc">Error callback for allocator errors. </div><div class="ttdef"><b>Definition:</b> opalloc_test.c:400</div></div>
<div class="ttc" id="group__llinterface_html_gac5c6703fea3c0a2e39d07f4bfac031a8"><div class="ttname"><a href="group__llinterface.html#gac5c6703fea3c0a2e39d07f4bfac031a8">op_ll_deallocate_object</a></div><div class="ttdeci">void op_ll_deallocate_object(op_allocator allocator, const void *object)</div><div class="ttdoc">Deallocate a specified object from the given allocator. </div><div class="ttdef"><b>Definition:</b> opalloc.c:110</div></div>
<div class="ttc" id="group__llinterface_html_ga278159fc6bbfb1c2e2513530cbee0e96"><div class="ttname"><a href="group__llinterface.html#ga278159fc6bbfb1c2e2513530cbee0e96">op_ll_deinitialize_allocator</a></div><div class="ttdeci">void op_ll_deinitialize_allocator(op_allocator allocator)</div><div class="ttdoc">De-initialize an allocator, freeing any owned resources. </div><div class="ttdef"><b>Definition:</b> opalloc.c:129</div></div>
<div class="ttc" id="group__llinterface_html_ga9209b1a64c38a2148ea7c25dab8edd0f"><div class="ttname"><a href="group__llinterface.html#ga9209b1a64c38a2148ea7c25dab8edd0f">op_allocator</a></div><div class="ttdeci">struct _op_allocator * op_allocator</div><div class="ttdoc">Opaque allocator handle permitting multiple object pools. </div><div class="ttdef"><b>Definition:</b> opalloc.h:56</div></div>
<div class="ttc" id="structop__allocator__stats_html_a0121145290507112e4e08e9196c00ab5"><div class="ttname"><a href="structop__allocator__stats.html#a0121145290507112e4e08e9196c00ab5">op_allocator_stats::maximum_objects</a></div><div class="ttdeci">size_t maximum_objects</div><div class="ttdef"><b>Definition:</b> opalloc.h:62</div></div>
<div class="ttc" id="group__llinterface_html_gaa0d8acd3d49cc322551e0033f61bdaca"><div class="ttname"><a href="group__llinterface.html#gaa0d8acd3d49cc322551e0033f61bdaca">op_ll_get_allocator_stats</a></div><div class="ttdeci">op_allocator_stats op_ll_get_allocator_stats(const op_allocator allocator)</div><div class="ttdoc">De-initialize an allocator, freeing any owned resources. </div><div class="ttdef"><b>Definition:</b> opalloc.c:171</div></div>
<div class="ttc" id="group__llinterface_html_ga92340cf30ad310a00d2f24ac2f480156"><div class="ttname"><a href="group__llinterface.html#ga92340cf30ad310a00d2f24ac2f480156">op_ll_allocate_object</a></div><div class="ttdeci">void * op_ll_allocate_object(op_allocator allocator)</div><div class="ttdoc">Allocate an object in the given allocator context. </div><div class="ttdef"><b>Definition:</b> opalloc.c:51</div></div>
<div class="ttc" id="group__llinterface_html_gga27f4549e49590119789d18e1ff77e7c0a840daf6b7aadca424c38454f5755aa8c"><div class="ttname"><a href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0a840daf6b7aadca424c38454f5755aa8c">OP_DOUBLING_CHUNK</a></div><div class="ttdef"><b>Definition:</b> opalloc.h:50</div></div>
<div class="ttc" id="group__llinterface_html_gaf0ba071e1d766a1e7cb9ba7c40d5b4ba"><div class="ttname"><a href="group__llinterface.html#gaf0ba071e1d766a1e7cb9ba7c40d5b4ba">op_ll_initialize_allocator</a></div><div class="ttdeci">op_allocator op_ll_initialize_allocator(const size_t object_size, const size_t initial_count, const op_ll_allocator_mode mode)</div><div class="ttdoc">Initialize an allocator according to the provided configuration. </div><div class="ttdef"><b>Definition:</b> opalloc.c:187</div></div>
<div class="ttc" id="struct__op__allocator_html"><div class="ttname"><a href="struct__op__allocator.html">_op_allocator</a></div><div class="ttdef"><b>Definition:</b> opalloc.c:36</div></div>
<div class="ttc" id="group__llinterface_html_ga27f4549e49590119789d18e1ff77e7c0"><div class="ttname"><a href="group__llinterface.html#ga27f4549e49590119789d18e1ff77e7c0">op_ll_allocator_mode</a></div><div class="ttdeci">op_ll_allocator_mode</div><div class="ttdoc">Allocator mode handling. </div><div class="ttdef"><b>Definition:</b> opalloc.h:47</div></div>
<div class="ttc" id="group__llinterface_html_gga27f4549e49590119789d18e1ff77e7c0acd93e093157aa38ebc1a5b9633e7755e"><div class="ttname"><a href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0acd93e093157aa38ebc1a5b9633e7755e">OP_DOUBLING_INDIVIDUAL</a></div><div class="ttdef"><b>Definition:</b> opalloc.h:49</div></div>
<div class="ttc" id="group__llinterface_html_gad09821373eccfb78a54f20dbf5d4bdd2"><div class="ttname"><a href="group__llinterface.html#gad09821373eccfb78a54f20dbf5d4bdd2">op_allocator_stats</a></div><div class="ttdeci">struct op_allocator_stats op_allocator_stats</div><div class="ttdoc">Stats for measuring and debugging allocators. </div></div>
<div class="ttc" id="group__llinterface_html_gga27f4549e49590119789d18e1ff77e7c0af55c441a5deea02b96b61bdd18fb5aff"><div class="ttname"><a href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0af55c441a5deea02b96b61bdd18fb5aff">OP_LINEAR_INDIVIDUAL</a></div><div class="ttdef"><b>Definition:</b> opalloc.h:51</div></div>
<div class="ttc" id="structop__allocator__stats_html_a562d1a6a3feee1f423eb96d40b9f91d2"><div class="ttname"><a href="structop__allocator__stats.html#a562d1a6a3feee1f423eb96d40b9f91d2">op_allocator_stats::active_objects</a></div><div class="ttdeci">size_t active_objects</div><div class="ttdef"><b>Definition:</b> opalloc.h:63</div></div>
<div class="ttc" id="group__llinterface_html_gga27f4549e49590119789d18e1ff77e7c0aa7777bc69f8c511bd503ca7ac68a1096"><div class="ttname"><a href="group__llinterface.html#gga27f4549e49590119789d18e1ff77e7c0aa7777bc69f8c511bd503ca7ac68a1096">OP_LINEAR_CHUNK</a></div><div class="ttdef"><b>Definition:</b> opalloc.h:52</div></div>
<div class="ttc" id="structop__allocator__stats_html_a15a79503b219194c76a468bdc3bec4a5"><div class="ttname"><a href="structop__allocator__stats.html#a15a79503b219194c76a468bdc3bec4a5">op_allocator_stats::object_size</a></div><div class="ttdeci">size_t object_size</div><div class="ttdef"><b>Definition:</b> opalloc.h:61</div></div>
<div class="ttc" id="structop__allocator__stats_html"><div class="ttname"><a href="structop__allocator__stats.html">op_allocator_stats</a></div><div class="ttdoc">Stats for measuring and debugging allocators. </div><div class="ttdef"><b>Definition:</b> opalloc.h:59</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
